<?php
namespace Client\Controller;
use Think\Controller;
class IndexController extends BaseController{
//class IndexController extends Controller{
	
	//========================
	protected function _initialize(){
		parent::_initialize();
		header("Content-Type: text/html;charset=utf-8");
		$this->assign('tj',time());
		$this->assign('session',$_SESSION);
		
		//p($_SESSION);
	}
	
	//首页
    public function index(){
    		$this->wxsdk();		//使用微信SDK
    		
		//首页轮播图集
		$ads=M('ads')->select();
		foreach($ads as $k=>$v){
			$listpic=$this->getPic($v['pic']);
			$ads[$k]['imgurl']=$listpic['imgurl'];
		}
		$this->assign('indexalbum',$ads);	
		$this->display();
    }
	//普洗-件
    public function poorwash_jian(){
		$this->display();
    }
	//普洗-袋
    public function poorwash_dai(){
		$this->display();
    }
	//品牌精洗
	public function brandwash(){
		
		$this->display();
	}
	//洗鞋
	public function shoeswash(){
		$this->display();
	}
	//洗涤救治
	public function curewash(){
		$this->display();
	}
	
	
	//预约页面
	public function reserve(){
		$typeid=I('typeid');
		$is_dai_jian=I('is_dai_jian') ? I('is_dai_jian') : 0;
		$id = isset($_GET['id']) ? $_GET['id'] : false;
		foreach (self::$entry as $k => $v) {
			if($k==$typeid){
				$this->assign('typename',$v);
			}
		}
		if($typeid || $is_dai_jian){
			$daitype=I('daitype');
			$this->assign('daitype',$daitype);
			$this->assign('typeid',$typeid);
			$this->assign('is_dai_jian',$is_dai_jian);
		}
		
		$addresslist=M('bb_address')->where(array('openid'=>$_SESSION['openid']))->select();
		$defaddress='';
		foreach ($addresslist as $k => $v) {
			if($v['is_def']==1){
				$defaddress=$v;
			}
		}
		$this->assign('defaddress',$defaddress);
		$this->assign('addresslist',$addresslist);
		
		
		$area=$this->area_data();
		$area=\bb\Data::channelLevel($area, $_SESSION['city']['pid'], '-', 'area_id');
		$this->assign('area',$area);
		$this->display();
    }
	
	//预约页面
	public function reserve_ok(){
		$this->wxsdk();		//使用微信SDK
		
		$user=M('client_user')->where(array('openid'=>$_SESSION['openid']))->find();
		$this->assign('user',$user);
		$this->display();
    }
	
	//家政服务
	public function housekeeping(){
		$this->display();
    }
	//奢侈品护理
	public function luxury(){
		$this->display();
	}
	//如何选择
	public function how_to_choose(){
		$this->display();
	}
	//常见问题
	public function common_problem(){
		$this->display();
	}
	//如何洗涤
	public function howwashing(){
		$this->display();
	}
	//上线的新闻
	public function onlinenews(){
		$this->display();
    }
	//关于我们
	public function rules(){
		$this->display();
	}
	//=微信SDK============================
	public function wxsdk(){
		//分享js 参数------------------------------
		$options['appid']=C('BB_APPID_client');
		$options['secret']=C('BB_SECRET_client');
		$wx=new \bb\Wechat($options);	//new 微信类
		$rejsapi=$wx->getjsapi();
		$this->assign('jsapi',$rejsapi);
		//-----------------------------------
	}
	public function area_data(){
		//缓存地区信息
		//S('privince',null);
		$authname='privince';
		if($rs = S($authname)){
			return $rs;
		}else{
			$area=M('bb_area')->select();
			$expire = 60*60*24;	//每天缓存一次
			S($authname,$area,$expire);
			return $area;
		}
	}
	
	//获取单张图片
	public function getPic($id){
		$m=M('weixin_upload_img');
		$map['id']=$id;
		$list=$m->where($map)->find();
		if($list){
			$list['imgurl']="/Upload/".$list['savepath'].$list['savename'];
		}
		return $list?$list:"";
	}
	
}